﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AvvaMobileNHibernateHelperKit.Controls
{
    public partial class NewsList : UserControl
    {
        public NewsList()
        {
            InitializeComponent();
        }

        private void NewsList_Load(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                DataSet ds = new DataSet();
                ds.ReadXml(SystemFileNames.NEWS_LIST_FILE);

                int top = 2;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    NewsListItem li = new NewsListItem(dr["NewsTitle"].ToString(), dr["NewsDescription"].ToString());
                    li.Top = top;
                    li.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left))));
                    this.pnlContent.Controls.Add(li);
                    top += li.Height + 10;
                }
            }
            catch
            {
                NewsListItem li = new NewsListItem("You have not internet connection or can not connect to news server.", "");
                li.AllowOpenBrowser = false;
                this.pnlContent.Controls.Add(li);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }


    }
}
